package cn.kgc.service.impl;


import cn.kgc.entity.Comment;
import cn.kgc.mapper.CommentMapper;
import cn.kgc.service.CommentService;
import cn.kgc.util.PageBeanHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liyuzhen
 * @date 2022/1/12 11:55
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentMapper commentMapper;

    @Override
    public PageBeanHelper<Comment> getComment(Integer shopId, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Comment> comments = commentMapper.getComment(shopId);
        PageInfo<Comment> commentPageInfo = new PageInfo<>(comments);


        PageBeanHelper<Comment> commentPages =new PageBeanHelper<>();
        //当前页
        commentPages.setPageNumber(commentPageInfo.getPageNum());
        commentPages.setPageSize(commentPageInfo.getPageSize());
        //总记录数
        commentPages.setPageCount((int) commentPageInfo.getTotal());
        //总页数
        commentPages.setPageTotal(commentPageInfo.getPages());
        //数据
        commentPages.setResultList(comments);
        return commentPages ;
    }
}
